
export const init = (self, tiyData) => {

  tiyData.tParam.selectedTabId='';
  tiyData.tData.productList.splice(0,tiyData.tData.productList.length );
  self.$apiProduct.getTabs({
   }).then(function(response){
    tiyData.tData.tabs.length=0;
     if(response.success){
       response.result.forEach(function(item){
         tiyData.tData.tabs.push(item);
       })

     }
  });
}

export const webList = (self, tiyData) => {

  if(tiyData.tParam.selectedTabId==''){
    self.$Message.error("请选择角标");
    return;
  }
  self.$Spin.show();
  tiyData.tData.productList.splice(0,tiyData.tData.productList.length );
  self.$apiProduct.getProductTabs({
    "pageSize": tiyData.tPage.stepNumber,
    "pageNum": tiyData.tPage.currentPage,
    "productCode": tiyData.tParam.productCode,
    "selectedTabId": tiyData.tParam.selectedTabId,
    "operation": tiyData.tParam.operation,
    "productName": tiyData.tParam.productName
  }).then(function (response) {
      self.$Spin.hide();
      if (response.success) {
        tiyData.tParam.length = [];
        tiyData.tData.productList.length = 0;
        let productPage = response.result;
        tiyData.tPage.total = productPage.total;
        tiyData.tPage.stepNumber = productPage.pageSize;
        productPage.list.forEach(
          function (item) {
            tiyData.tData.productList.push(item);
          }
        );
        if (0 == tiyData.tData.productList.length) {
          self.$Message.error("查询没有结果");
        }
      } else {
        self.$Spin.hide();
        self.$Message.error(response.errorMessage);
      }
    });
};

export const batchOperation = (self, tiyData) =>{
  self.loadingData = true;
  self.$Spin.show();
  let productIds=[];
  tiyData.tParam.selection.forEach(
    function(selected,index){
      productIds.push(selected.id)
    }
  )
    self.$apiProduct.batchEditProductTab({
      "productIds": productIds.toString(),
      "tabId": tiyData.tParam.selectedTabId,
      "operation": tiyData.tParam.operation,
    })
      .then(function (response) {
        // self.$Spin.hide();刷新列表后隐藏
        self.loadingData = false;
        if (response.success) {
          tiyData.tParam.length = [];
          tiyData.tData.productList.length = 0;
          self.$Message.success("操作成功");
          tiyData.tParam.selection.length=0;
          self.webList();
        } else {
          self.$Spin.hide();
          self.$Message.error(response.errorMessage);
        }
      });

  }
